
# 2003 web projects check for project type = web and display error or throw
param ($RootDirectory, [switch]$FailOnFind)

# get the list of projects
$projects = Get-ChildItem $RootDirectory -filter '*.*proj'  -Recurse

# find all lines with "<hintpath>" then exclude ones that don't contain dependencies or libs
[array]$WebProject = $projects | Select-String "ProjectType" | Where-Object {($_.Line -match "web")}
		
#Report Results
if ($WebProject)
{
	if (-not $FailOnFind)
	{
	  Write-Host "=============================================================================================="
	  $WebProject | %{ Write-Warning "ProjectType 'Web' found in $($_.Path) Line: $($_.LineNumber) - $($_.Line.Trim())" }
	  Write-Host "=============================================================================================="
		Write-Host "$($WebProject.count) ProjectType(s) 'Web' found."
	}	

	if ($FailOnFind)
	{
	  Write-Host "=============================================================================================="
		$WebProject | %{ Write-host "ProjectType 'Web' found in $($_.Path) Line: $($_.LineNumber) - $($_.Line.Trim())" -foregroundcolor red}
	  Write-Host "=============================================================================================="
		Throw "$($WebProject.count) ProjectType(s) 'Web' found."
	}
	
}
Write-Host "Find-2003WebProjects.ps1 script completed"
